package IO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Demo05 {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = null;
        try{
            //        InputStream inputStream = new InputStream();
//        不能实例化，抽象类
            inputStream = new FileInputStream("d:/test.txt");
            while(true){
//             int b = inputStream.read();
//             if (b == -1){
////                 读取完毕
//                 break;
//             }
////             大写
////             System.out.printf("0x%X ",b);
//             System.out.printf("0x%x ",b);

                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if (n == -1) {
//                 读取完毕，n就是-1
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("0x%x ",bytes[i]);
                }
                System.out.println();
        }
        } finally {
            inputStream.close();
        }

         inputStream.close();
//         无参数，一次读取一个字节
//         inputStream.read();
//         带有参数，参数表示返回结果
//         提前准备好数组
//         byte[] bytes = new byte[1024];
//         inputStream.read(bytes);
    }
}
